from django.db import models


class BaseModel(models.Model):
    create_time = models.DateTimeField(
        verbose_name='创建时间', null=True, blank=True, auto_now_add=True)
    update_time = models.DateTimeField(
        verbose_name='更新时间', null=True, blank=True, auto_now=True)

    class Meta:
        abstract = True


class Codes(BaseModel):
    dm = models.CharField(verbose_name="code_number", default="0000000", null=False, blank=False, max_length=32,
                          unique=True)
    mc = models.CharField(verbose_name="code_name", default="Unknown", null=False, blank=False, max_length=32)
    jys = models.CharField(verbose_name="code_type", default="Unknown", null=False, blank=False, max_length=32)

    class Meta:
        managed = True
        db_table = 'codes'


class Record(BaseModel):
    dm_id = models.ForeignKey(Codes, on_delete=models.CASCADE, to_field='dm')
    d = models.CharField(verbose_name="day", default="1900-01-01", null=False, blank=True, max_length=32)
    # 新增字段用于判读文件是替换的还是新增。
    o = models.CharField(verbose_name="0", default="-1", null=False, blank=True, max_length=32)
    h = models.CharField(verbose_name="h", default="-1", null=False, blank=True, max_length=32)
    l = models.CharField(verbose_name="l", default="-1", null=False, blank=True, max_length=32)
    c = models.CharField(verbose_name="c", default="-1", null=False, blank=True, max_length=32)
    v = models.CharField(verbose_name="v", default="-1", null=False, blank=True, max_length=64)
    e = models.CharField(verbose_name="e", default="-1", null=False, blank=True, max_length=64)
    zf = models.CharField(verbose_name="zf", default="-1", null=False, blank=True, max_length=32)
    hs = models.CharField(verbose_name="hs", default="-1", null=False, blank=True, max_length=32)
    zd = models.CharField(verbose_name="zd", default="-1", null=False, blank=True, max_length=32)
    zde = models.CharField(verbose_name="zde", default="-1", null=False, blank=True, max_length=32)

    class Meta:
        managed = True
        db_table = 'record'
        indexes = [
            models.Index(fields=["d"]),
        ]
